#ifndef OHOS_RIVE_GENERAL_H
#define OHOS_RIVE_GENERAL_H

#include "helpers/render_type.h"
#include "rive/factory.hpp"
#include "rive/file_asset_loader.hpp"
#include <hilog/log.h>
#include <napi/native_api.h>
#include <uv.h>

namespace ohos_rive {

// Print only on debug builds.
#if defined(DEBUG) || defined(LOG)
#define RIVE_LOG_TAG "OHOS_RIVE"
#define RIVE_LOG_DOMAIN 0xD0115B0
#define LOGE(...) OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_DOMAIN, "OHOS_RIVE", __VA_ARGS__)
#define LOGW(...) OH_LOG_Print(LOG_APP, LOG_WARN, LOG_DOMAIN, "OHOS_RIVE", __VA_ARGS__)
#define LOGD(...) OH_LOG_Print(LOG_APP, LOG_DEBUG, LOG_DOMAIN, "OHOS_RIVE", __VA_ARGS__)
#define LOGI(...) OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "OHOS_RIVE", __VA_ARGS__)
#define EGL_ERR_CHECK() _check_egl_error(__FILE__, __LINE__)
#else
#define LOGE(...)
#define LOGW(...)
#define LOGD(...)
#define LOGI(...)
#define EGL_ERR_CHECK()
#endif

extern long g_systemVersion;
void SetSystemVersion();

uint64_t Import(napi_env env,
                uint8_t *data,
                int32_t length,
                RendererType rendererType = RendererType::Rive,
                rive::FileAssetLoader *assetLoader = nullptr);

rive::Alignment GetAlignment(napi_env env, napi_value jsAlignment);
rive::Fit GetFit(napi_env env, napi_value jsFit);
rive::Factory *GetFactory(RendererType rendererType);

void DetachThread();

std::string NapiStringToString(napi_env env, napi_value jsString);
int32_t SizeTToInt(size_t value);
size_t NapiIntToSizeT(napi_env env, napi_value jsValue);

#if defined(DEBUG) || defined(LOG)
// luigi: this redirects stderr to android log (probably want to ifdef this
// out for release)
[[noreturn]] void LogThread();
void _check_egl_error(const char *, int);
#endif

} // namespace ohos_rive
#endif // OHOS_RIVE_GENERAL_H
